<!-- 左部菜单-开始 -->
<div class="layui-col-md2" id="left_menus" style="display: none;">
    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="demo" style="margin-right: 10px;">
        <li class="layui-nav-item layui-nav-itemed">
            <a href="javascript:;">会员中心</a>
            <dl class="layui-nav-child" id="sub_menus">
                <dd><a href="user.html">基本信息</a></dd>
                <dd><a href="user-dev.html">开发配置</a></dd>
                <dd><a href="user-links.html">调用记录</a></dd>
            </dl>
        </li>
        <li class="layui-nav-item layui-nav-itemed">
            <a href="javascript:;" id="logout">退出系统</a>
        </li>
    </ul>
</div>
<!-- 左部菜单-结束 -->
<script>
layui.use('jquery', function() { 
    var $ = jQuery;
    var auth_string = window.localStorage.getItem('authorization');
    if (!auth_string || auth_string === '') { 
        top.location.href = '/login.html';
    }

    $("#left_menus").show();

    var path = location.pathname.substring(1);
    $("a", $("#sub_menus")).each(function() { 
        var that = $(this);
        var url = that.attr("href");
        if (path === url) { 
            that.attr("style", "color: #aaa");
        }   
    });

    $(document).on('click', '#logout', function() { 
        layer.open({
            content: '你确认要退出系统登录么?',
            btn: ['确定', '取消'],
            yes: function() { 
                $.ajax({
                    url: get_api_url("auth/users/logout"),
                    headers: {
                        "Authorization": 'Bearer ' + window.localStorage.getItem('authorization')
                    },
                    dataType: "json",
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    success: function(res) { 
                        window.localStorage.removeItem("authorization");
                        top.location.href = "/login.html";
                    }
                });
            },
            cancel: function() { }
        })
    });
});
</script>
